package com.ruiysoft.controller.statement.util;

import com.ruiysoft.entity.statement.StatementShop;
import com.ruiysoft.entity.statement.StatementUser;
import com.ruiysoft.pub.consts.EnumUtil;
import com.ruiysoft.service.statement.consts.StatementStatus;
import com.ruiysoft.util.NumberUtils;
import com.ruiysoft.util.RegularUtil;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;
import java.util.Objects;

public class StatementUtil {
    public static Boolean getStatus(StatementShop statement) {
        if(statement==null){
            return false;
        }
        if(Objects.equals(true,statement.getFreeze())){
            return false;
        }else return statement.getArrivalDate() != null && new Date().compareTo(statement.getArrivalDate()) >= 0;
    }

    public static Boolean getStatus(StatementUser statement) {
        if(statement==null){
            return false;
        }
        if(Objects.equals(true,statement.getFreeze())){
            return false;
        }else return statement.getArrivalDate() != null && new Date().compareTo(statement.getArrivalDate()) >= 0;
    }


    public static Long valiPrice(String s, EnumUtil.Required required) throws RuntimeException {
        String price = s;
        switch (required) {
            case YES:
                if(StringUtils.isBlank(price)){
                    throw new IllegalArgumentException("金额不能为空");
                }
                if (!RegularUtil.isMoney(price))
                    throw new IllegalArgumentException("金额错误");
                return Long.parseLong(NumberUtils.changeY2F(price));
            case NO:
                if (price != null) {
                    if (!RegularUtil.isMoney(price))
                        throw new IllegalArgumentException("金额错误");
                    return Long.parseLong(NumberUtils.changeY2F(price));
                }
                return null;
        }
        return null;
    }
}
